package org.spindle.soasuite.controllers;

import org.spindle.soasuite.core.api.AExecutable;
import org.spindle.soasuite.core.api.annotations.Executable;
import org.spindle.soasuite.core.api.annotations.Parameter;
import org.spindle.soasuite.datasource.external.DatasourceManager;

@Executable(path = "/devel")
class DevelopmentController extends AExecutable {

    @Parameter(name = "m")
    private String method;

    @Override
    public Object execute() {
        DatasourceManager manager = new DatasourceManager();
        if ("cleanup".equals(method)) {
            try {
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "delete from configuration");
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "delete from jdbc_connection");
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "delete from mock_service");
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "delete from project");
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "delete from user");
                manager.execute("com.mysql.jdbc.Driver", "jdbc:mysql://localhost:3306/soasuite", "root", "fckgwq9tj9", "insert into user values (null, 'admin','admin','admin','admin')");
            } catch (Exception e) {
                e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
            }
        }

        return null;
    }

    @Override
    public String getName() {
        return "Development controller";
    }
}
